{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "023d771c",
      "metadata": {
        "id": "023d771c"
      },
      "source": [
        "[![Open nbviewer](https://raw.githubusercontent.com/pinecone-io/examples/master/assets/nbviewer-shield.svg)](https://nbviewer.org/github/pinecone-io/examples/blob/master/learn/search/semantic-search/hello-pinecone-aws.ipynb)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "conceptual-belfast",
      "metadata": {
        "id": "conceptual-belfast",
        "papermill": {
          "duration": 0.028714,
          "end_time": "2021-04-16T15:08:30.639231",
          "exception": false,
          "start_time": "2021-04-16T15:08:30.610517",
          "status": "completed"
        },
        "tags": []
      },
      "source": [
        "# Hello, Pinecone!\n",
        "\n",
        "This notebook will walk through the steps to get a simple Pinecone index up and running on AWS.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "first-affairs",
      "metadata": {
        "id": "first-affairs",
        "papermill": {
          "duration": 0.025469,
          "end_time": "2021-04-16T15:08:30.690710",
          "exception": false,
          "start_time": "2021-04-16T15:08:30.665241",
          "status": "completed"
        },
        "tags": []
      },
      "source": [
        "## Prerequisites"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "banned-huntington",
      "metadata": {
        "id": "banned-huntington",
        "papermill": {
          "duration": 0.023078,
          "end_time": "2021-04-16T15:08:30.737798",
          "exception": false,
          "start_time": "2021-04-16T15:08:30.714720",
          "status": "completed"
        },
        "tags": []
      },
      "source": [
        "Install dependencies."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "id": "parallel-detective",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "execution": {
          "iopub.execute_input": "2021-04-16T15:08:30.790085Z",
          "iopub.status.busy": "2021-04-16T15:08:30.789322Z",
          "iopub.status.idle": "2021-04-16T15:08:48.879840Z",
          "shell.execute_reply": "2021-04-16T15:08:48.880935Z"
        },
        "id": "parallel-detective",
        "outputId": "8dc9dc6d-5a02-4699-df31-fe28da170865",
        "papermill": {
          "duration": 18.119125,
          "end_time": "2021-04-16T15:08:48.881643",
          "exception": false,
          "start_time": "2021-04-16T15:08:30.762518",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/421.4 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m419.8/421.4 kB\u001b[0m \u001b[31m14.4 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m421.4/421.4 kB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h"
          ]
        }
      ],
      "source": [
        "!pip install -qU \\\n",
        "  pinecone==6.0.1 \\\n",
        "  pandas==2.2.2"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "191793df",
      "metadata": {
        "id": "191793df"
      },
      "source": [
        "## Initializing the Index\n",
        "\n",
        "Now we need a place to store these embeddings and enable a efficient vector search through them all. To do that we use Pinecone, we can get a [free API key](https://app.pinecone.io/) and enter it below where we will initialize our connection to Pinecone and create a new index."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "id": "3f0a5ee4",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "3f0a5ee4",
        "outputId": "f26b6f73-7da4-43c7-eeb0-07c5fdfe5cff"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Enter your Pinecone API key··········\n"
          ]
        }
      ],
      "source": [
        "import os\n",
        "from pinecone import Pinecone\n",
        "from getpass import getpass\n",
        "\n",
        "# initialize connection to pinecone (get API key at app.pinecone.io)\n",
        "api_key = os.environ.get('PINECONE_API_KEY') or \\\n",
        "    getpass(\"Enter your Pinecone API key\")\n",
        "\n",
        "# configure client\n",
        "pc = Pinecone(api_key=api_key)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "forbidden-indication",
      "metadata": {
        "id": "forbidden-indication",
        "papermill": {
          "duration": 0.020515,
          "end_time": "2021-04-16T15:08:49.925687",
          "exception": false,
          "start_time": "2021-04-16T15:08:49.905172",
          "status": "completed"
        },
        "tags": []
      },
      "source": [
        "## Pinecone quickstart\n",
        "\n",
        "With Pinecone you can create a vector index where you can store and search through your vectors."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "id": "774014f4",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "774014f4",
        "outputId": "f5bfef00-6fdc-4754-9fc3-ce00b8d4cb88"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "[]"
            ]
          },
          "execution_count": 3,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "pc.list_indexes().names()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "id": "EA2EcZsCoWS3",
      "metadata": {
        "id": "EA2EcZsCoWS3",
        "tags": [
          "parameters"
        ]
      },
      "outputs": [],
      "source": [
        "# Giving our index a name\n",
        "index_name = \"hello-pinecone\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "id": "synthetic-essex",
      "metadata": {
        "execution": {
          "iopub.execute_input": "2021-04-16T15:08:49.974096Z",
          "iopub.status.busy": "2021-04-16T15:08:49.972856Z",
          "iopub.status.idle": "2021-04-16T15:08:50.392796Z",
          "shell.execute_reply": "2021-04-16T15:08:50.391552Z"
        },
        "id": "synthetic-essex",
        "papermill": {
          "duration": 0.446682,
          "end_time": "2021-04-16T15:08:50.393195",
          "exception": false,
          "start_time": "2021-04-16T15:08:49.946513",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [],
      "source": [
        "# Delete the index, if an index of the same name already exists\n",
        "if pc.has_index(name=index_name):\n",
        "    pc.delete_index(name=index_name)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "786a88df",
      "metadata": {
        "id": "786a88df"
      },
      "source": [
        "### Creating a Pinecone Index\n",
        "\n",
        "When creating the index we need to define several configuration properties.\n",
        "\n",
        "- `name` can be anything we like. The name is used as an identifier for the index when performing other operations such as `describe_index`, `delete_index`, and so on.\n",
        "- `metric` specifies the similarity metric that will be used later when you make queries to the index.\n",
        "- `dimension` should correspond to the dimension of the dense vectors produced by your embedding model. In this quick start, we are using made-up data so a small value is simplest.\n",
        "- `spec` holds a specification which tells Pinecone how you would like to deploy our index. You can find a list of all [available providers and regions here](https://docs.pinecone.io/troubleshooting/available-cloud-regions).\n",
        "\n",
        "There are more configurations available, but this minimal set will get us started."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "id": "4YwC8livCrn2",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "execution": {
          "iopub.execute_input": "2021-04-16T15:08:50.497478Z",
          "iopub.status.busy": "2021-04-16T15:08:50.496767Z",
          "iopub.status.idle": "2021-04-16T15:09:04.224132Z",
          "shell.execute_reply": "2021-04-16T15:09:04.223529Z"
        },
        "id": "4YwC8livCrn2",
        "outputId": "5de1d905-2c7a-425e-8c30-60fc84c2e5b7",
        "papermill": {
          "duration": 13.756687,
          "end_time": "2021-04-16T15:09:04.224466",
          "exception": false,
          "start_time": "2021-04-16T15:08:50.467779",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{\n",
              "    \"name\": \"hello-pinecone\",\n",
              "    \"metric\": \"cosine\",\n",
              "    \"host\": \"hello-pinecone-rjeaip3.svc.aped-4627-b74a.pinecone.io\",\n",
              "    \"spec\": {\n",
              "        \"serverless\": {\n",
              "            \"cloud\": \"aws\",\n",
              "            \"region\": \"us-east-1\"\n",
              "        }\n",
              "    },\n",
              "    \"status\": {\n",
              "        \"ready\": true,\n",
              "        \"state\": \"Ready\"\n",
              "    },\n",
              "    \"vector_type\": \"dense\",\n",
              "    \"dimension\": 3,\n",
              "    \"deletion_protection\": \"disabled\",\n",
              "    \"tags\": null\n",
              "}"
            ]
          },
          "execution_count": 6,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "from pinecone import ServerlessSpec, CloudProvider, AwsRegion, Metric\n",
        "\n",
        "pc.create_index(\n",
        "    name=index_name,\n",
        "    metric=Metric.COSINE,\n",
        "    dimension=3,\n",
        "    spec=ServerlessSpec(\n",
        "        cloud=CloudProvider.AWS,\n",
        "        region=AwsRegion.US_EAST_1\n",
        "    )\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "id": "toy-VhU4LO_O",
      "metadata": {
        "execution": {
          "iopub.execute_input": "2021-04-16T15:09:04.283700Z",
          "iopub.status.busy": "2021-04-16T15:09:04.282289Z",
          "iopub.status.idle": "2021-04-16T15:09:05.096982Z",
          "shell.execute_reply": "2021-04-16T15:09:05.096019Z"
        },
        "id": "toy-VhU4LO_O",
        "papermill": {
          "duration": 0.846255,
          "end_time": "2021-04-16T15:09:05.097384",
          "exception": false,
          "start_time": "2021-04-16T15:09:04.251129",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [],
      "source": [
        "index = pc.Index(name=index_name)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "j1F8SLx6C2HH",
      "metadata": {
        "id": "j1F8SLx6C2HH",
        "papermill": {
          "duration": 0.023037,
          "end_time": "2021-04-16T15:09:05.153116",
          "exception": false,
          "start_time": "2021-04-16T15:09:05.130079",
          "status": "completed"
        },
        "tags": []
      },
      "source": [
        "We have the index ready. Now we will create some simple vectors that will serve as our examples."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "id": "indirect-lafayette",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 125
        },
        "execution": {
          "iopub.execute_input": "2021-04-16T15:09:05.206498Z",
          "iopub.status.busy": "2021-04-16T15:09:05.205699Z",
          "iopub.status.idle": "2021-04-16T15:09:05.404333Z",
          "shell.execute_reply": "2021-04-16T15:09:05.403743Z"
        },
        "id": "indirect-lafayette",
        "outputId": "45d4e1c9-0364-4440-9d2d-23db95b74339",
        "papermill": {
          "duration": 0.227373,
          "end_time": "2021-04-16T15:09:05.404700",
          "exception": false,
          "start_time": "2021-04-16T15:09:05.177327",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [
        {
          "data": {
            "application/vnd.google.colaboratory.intrinsic+json": {
              "summary": "{\n  \"name\": \"df\",\n  \"rows\": 2,\n  \"fields\": [\n    {\n      \"column\": \"id\",\n      \"properties\": {\n        \"dtype\": \"string\",\n        \"num_unique_values\": 2,\n        \"samples\": [\n          \"B\",\n          \"A\"\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"vector\",\n      \"properties\": {\n        \"dtype\": \"object\",\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}",
              "type": "dataframe",
              "variable_name": "df"
            },
            "text/html": [
              "\n",
              "  <div id=\"df-c392925a-8c2b-4f49-ae9f-34a02d371937\" class=\"colab-df-container\">\n",
              "    <div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>id</th>\n",
              "      <th>vector</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>A</td>\n",
              "      <td>[1.0, 1.0, 1.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>B</td>\n",
              "      <td>[1.0, 2.0, 3.0]</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>\n",
              "    <div class=\"colab-df-buttons\">\n",
              "\n",
              "  <div class=\"colab-df-container\">\n",
              "    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c392925a-8c2b-4f49-ae9f-34a02d371937')\"\n",
              "            title=\"Convert this dataframe to an interactive table.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
              "    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "\n",
              "  <style>\n",
              "    .colab-df-container {\n",
              "      display:flex;\n",
              "      gap: 12px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert {\n",
              "      background-color: #E8F0FE;\n",
              "      border: none;\n",
              "      border-radius: 50%;\n",
              "      cursor: pointer;\n",
              "      display: none;\n",
              "      fill: #1967D2;\n",
              "      height: 32px;\n",
              "      padding: 0 0 0 0;\n",
              "      width: 32px;\n",
              "    }\n",
              "\n",
              "    .colab-df-convert:hover {\n",
              "      background-color: #E2EBFA;\n",
              "      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "      fill: #174EA6;\n",
              "    }\n",
              "\n",
              "    .colab-df-buttons div {\n",
              "      margin-bottom: 4px;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert {\n",
              "      background-color: #3B4455;\n",
              "      fill: #D2E3FC;\n",
              "    }\n",
              "\n",
              "    [theme=dark] .colab-df-convert:hover {\n",
              "      background-color: #434B5C;\n",
              "      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "      fill: #FFFFFF;\n",
              "    }\n",
              "  </style>\n",
              "\n",
              "    <script>\n",
              "      const buttonEl =\n",
              "        document.querySelector('#df-c392925a-8c2b-4f49-ae9f-34a02d371937 button.colab-df-convert');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      async function convertToInteractive(key) {\n",
              "        const element = document.querySelector('#df-c392925a-8c2b-4f49-ae9f-34a02d371937');\n",
              "        const dataTable =\n",
              "          await google.colab.kernel.invokeFunction('convertToInteractive',\n",
              "                                                    [key], {});\n",
              "        if (!dataTable) return;\n",
              "\n",
              "        const docLinkHtml = 'Like what you see? Visit the ' +\n",
              "          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
              "          + ' to learn more about interactive tables.';\n",
              "        element.innerHTML = '';\n",
              "        dataTable['output_type'] = 'display_data';\n",
              "        await google.colab.output.renderOutput(dataTable, element);\n",
              "        const docLink = document.createElement('div');\n",
              "        docLink.innerHTML = docLinkHtml;\n",
              "        element.appendChild(docLink);\n",
              "      }\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "\n",
              "<div id=\"df-5433f1a8-2218-43d4-8e0c-ca9dc5119930\">\n",
              "  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-5433f1a8-2218-43d4-8e0c-ca9dc5119930')\"\n",
              "            title=\"Suggest charts\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "     width=\"24px\">\n",
              "    <g>\n",
              "        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
              "    </g>\n",
              "</svg>\n",
              "  </button>\n",
              "\n",
              "<style>\n",
              "  .colab-df-quickchart {\n",
              "      --bg-color: #E8F0FE;\n",
              "      --fill-color: #1967D2;\n",
              "      --hover-bg-color: #E2EBFA;\n",
              "      --hover-fill-color: #174EA6;\n",
              "      --disabled-fill-color: #AAA;\n",
              "      --disabled-bg-color: #DDD;\n",
              "  }\n",
              "\n",
              "  [theme=dark] .colab-df-quickchart {\n",
              "      --bg-color: #3B4455;\n",
              "      --fill-color: #D2E3FC;\n",
              "      --hover-bg-color: #434B5C;\n",
              "      --hover-fill-color: #FFFFFF;\n",
              "      --disabled-bg-color: #3B4455;\n",
              "      --disabled-fill-color: #666;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart {\n",
              "    background-color: var(--bg-color);\n",
              "    border: none;\n",
              "    border-radius: 50%;\n",
              "    cursor: pointer;\n",
              "    display: none;\n",
              "    fill: var(--fill-color);\n",
              "    height: 32px;\n",
              "    padding: 0;\n",
              "    width: 32px;\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart:hover {\n",
              "    background-color: var(--hover-bg-color);\n",
              "    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "    fill: var(--button-hover-fill-color);\n",
              "  }\n",
              "\n",
              "  .colab-df-quickchart-complete:disabled,\n",
              "  .colab-df-quickchart-complete:disabled:hover {\n",
              "    background-color: var(--disabled-bg-color);\n",
              "    fill: var(--disabled-fill-color);\n",
              "    box-shadow: none;\n",
              "  }\n",
              "\n",
              "  .colab-df-spinner {\n",
              "    border: 2px solid var(--fill-color);\n",
              "    border-color: transparent;\n",
              "    border-bottom-color: var(--fill-color);\n",
              "    animation:\n",
              "      spin 1s steps(1) infinite;\n",
              "  }\n",
              "\n",
              "  @keyframes spin {\n",
              "    0% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "      border-left-color: var(--fill-color);\n",
              "    }\n",
              "    20% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    30% {\n",
              "      border-color: transparent;\n",
              "      border-left-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    40% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-top-color: var(--fill-color);\n",
              "    }\n",
              "    60% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "    }\n",
              "    80% {\n",
              "      border-color: transparent;\n",
              "      border-right-color: var(--fill-color);\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "    90% {\n",
              "      border-color: transparent;\n",
              "      border-bottom-color: var(--fill-color);\n",
              "    }\n",
              "  }\n",
              "</style>\n",
              "\n",
              "  <script>\n",
              "    async function quickchart(key) {\n",
              "      const quickchartButtonEl =\n",
              "        document.querySelector('#' + key + ' button');\n",
              "      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n",
              "      quickchartButtonEl.classList.add('colab-df-spinner');\n",
              "      try {\n",
              "        const charts = await google.colab.kernel.invokeFunction(\n",
              "            'suggestCharts', [key], {});\n",
              "      } catch (error) {\n",
              "        console.error('Error during call to suggestCharts:', error);\n",
              "      }\n",
              "      quickchartButtonEl.classList.remove('colab-df-spinner');\n",
              "      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
              "    }\n",
              "    (() => {\n",
              "      let quickchartButtonEl =\n",
              "        document.querySelector('#df-5433f1a8-2218-43d4-8e0c-ca9dc5119930 button');\n",
              "      quickchartButtonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "    })();\n",
              "  </script>\n",
              "</div>\n",
              "\n",
              "  <div id=\"id_d3b238c9-ce87-4958-a184-2b61b563ccf7\">\n",
              "    <style>\n",
              "      .colab-df-generate {\n",
              "        background-color: #E8F0FE;\n",
              "        border: none;\n",
              "        border-radius: 50%;\n",
              "        cursor: pointer;\n",
              "        display: none;\n",
              "        fill: #1967D2;\n",
              "        height: 32px;\n",
              "        padding: 0 0 0 0;\n",
              "        width: 32px;\n",
              "      }\n",
              "\n",
              "      .colab-df-generate:hover {\n",
              "        background-color: #E2EBFA;\n",
              "        box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
              "        fill: #174EA6;\n",
              "      }\n",
              "\n",
              "      [theme=dark] .colab-df-generate {\n",
              "        background-color: #3B4455;\n",
              "        fill: #D2E3FC;\n",
              "      }\n",
              "\n",
              "      [theme=dark] .colab-df-generate:hover {\n",
              "        background-color: #434B5C;\n",
              "        box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
              "        filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
              "        fill: #FFFFFF;\n",
              "      }\n",
              "    </style>\n",
              "    <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n",
              "            title=\"Generate code using this dataframe.\"\n",
              "            style=\"display:none;\">\n",
              "\n",
              "  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
              "       width=\"24px\">\n",
              "    <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
              "  </svg>\n",
              "    </button>\n",
              "    <script>\n",
              "      (() => {\n",
              "      const buttonEl =\n",
              "        document.querySelector('#id_d3b238c9-ce87-4958-a184-2b61b563ccf7 button.colab-df-generate');\n",
              "      buttonEl.style.display =\n",
              "        google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
              "\n",
              "      buttonEl.onclick = () => {\n",
              "        google.colab.notebook.generateWithVariable('df');\n",
              "      }\n",
              "      })();\n",
              "    </script>\n",
              "  </div>\n",
              "\n",
              "    </div>\n",
              "  </div>\n"
            ],
            "text/plain": [
              "  id           vector\n",
              "0  A  [1.0, 1.0, 1.0]\n",
              "1  B  [1.0, 2.0, 3.0]"
            ]
          },
          "execution_count": 8,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "import pandas as pd\n",
        "\n",
        "df = pd.DataFrame(\n",
        "    data={\n",
        "        \"id\": [\"A\", \"B\"],\n",
        "        \"vector\": [[1., 1., 1.], [1., 2., 3.]]\n",
        "    })\n",
        "df"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "oiJKXWxoDjhK",
      "metadata": {
        "id": "oiJKXWxoDjhK",
        "papermill": {
          "duration": 0.022968,
          "end_time": "2021-04-16T15:09:05.452054",
          "exception": false,
          "start_time": "2021-04-16T15:09:05.429086",
          "status": "completed"
        },
        "tags": []
      },
      "source": [
        "We perform upsert operations in our index. This call will insert a new vector in the index or update the vector if the id was already present."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "id": "efficient-parliament",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "execution": {
          "iopub.execute_input": "2021-04-16T15:09:05.506668Z",
          "iopub.status.busy": "2021-04-16T15:09:05.505145Z",
          "iopub.status.idle": "2021-04-16T15:09:06.180038Z",
          "shell.execute_reply": "2021-04-16T15:09:06.179012Z"
        },
        "id": "efficient-parliament",
        "outputId": "d85df98f-9f86-40de-e545-d62d6ad1c13c",
        "papermill": {
          "duration": 0.704503,
          "end_time": "2021-04-16T15:09:06.180549",
          "exception": false,
          "start_time": "2021-04-16T15:09:05.476046",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{'upserted_count': 2}"
            ]
          },
          "execution_count": 9,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "# insert vectors\n",
        "index.upsert(\n",
        "    vectors=zip(df.id, df.vector)\n",
        ")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "id": "enclosed-performer",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "execution": {
          "iopub.execute_input": "2021-04-16T15:09:06.242684Z",
          "iopub.status.busy": "2021-04-16T15:09:06.241999Z",
          "iopub.status.idle": "2021-04-16T15:09:06.350759Z",
          "shell.execute_reply": "2021-04-16T15:09:06.351713Z"
        },
        "id": "enclosed-performer",
        "outputId": "8ede74dc-8ad2-4954-910b-eba701b7090a",
        "papermill": {
          "duration": 0.140473,
          "end_time": "2021-04-16T15:09:06.352169",
          "exception": false,
          "start_time": "2021-04-16T15:09:06.211696",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{'dimension': 3,\n",
              " 'index_fullness': 0.0,\n",
              " 'metric': 'cosine',\n",
              " 'namespaces': {'': {'vector_count': 2}},\n",
              " 'total_vector_count': 2,\n",
              " 'vector_type': 'dense'}"
            ]
          },
          "execution_count": 13,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "index.describe_index_stats()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "id": "leading-shape",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "execution": {
          "iopub.execute_input": "2021-04-16T15:09:06.422440Z",
          "iopub.status.busy": "2021-04-16T15:09:06.420935Z",
          "iopub.status.idle": "2021-04-16T15:09:08.564221Z",
          "shell.execute_reply": "2021-04-16T15:09:08.563202Z"
        },
        "id": "leading-shape",
        "outputId": "f3440980-cb64-48bf-e5fd-7b15bf0171da",
        "papermill": {
          "duration": 2.177493,
          "end_time": "2021-04-16T15:09:08.564594",
          "exception": false,
          "start_time": "2021-04-16T15:09:06.387101",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "{'matches': [{'id': 'A', 'score': 1.0, 'values': [1.0, 1.0, 1.0]}],\n",
              " 'namespace': '',\n",
              " 'usage': {'read_units': 6}}"
            ]
          },
          "execution_count": 14,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "# returns top_k matches\n",
        "index.query(\n",
        "    vector=[2., 2., 2.],\n",
        "    top_k=1,\n",
        "    include_values=True\n",
        ")"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "z5jcU5_SLMFC",
      "metadata": {
        "id": "z5jcU5_SLMFC",
        "papermill": {
          "duration": 0.035627,
          "end_time": "2021-04-16T15:09:08.629172",
          "exception": false,
          "start_time": "2021-04-16T15:09:08.593545",
          "status": "completed"
        },
        "tags": []
      },
      "source": [
        "## Delete the Index\n",
        "Delete the index once you are sure that you do not want to use it anymore. Once the index is deleted, you cannot use it again."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "id": "indian-broadcast",
      "metadata": {
        "execution": {
          "iopub.execute_input": "2021-04-16T15:09:08.698129Z",
          "iopub.status.busy": "2021-04-16T15:09:08.697250Z",
          "iopub.status.idle": "2021-04-16T15:09:21.171092Z",
          "shell.execute_reply": "2021-04-16T15:09:21.170231Z"
        },
        "id": "indian-broadcast",
        "papermill": {
          "duration": 12.505772,
          "end_time": "2021-04-16T15:09:21.171527",
          "exception": false,
          "start_time": "2021-04-16T15:09:08.665755",
          "status": "completed"
        },
        "tags": []
      },
      "outputs": [],
      "source": [
        "pc.delete_index(name=index_name)"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "e84d82ee",
      "metadata": {
        "id": "e84d82ee"
      },
      "source": [
        "---"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": ".venv",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.7"
    },
    "papermill": {
      "default_parameters": {},
      "duration": 52.201461,
      "end_time": "2021-04-16T15:09:21.730976",
      "environment_variables": {},
      "exception": null,
      "input_path": "/notebooks/quick_tour/hello_pinecone.ipynb",
      "output_path": "/notebooks/tmp/quick_tour/hello_pinecone.ipynb",
      "parameters": {},
      "start_time": "2021-04-16T15:08:29.529515",
      "version": "2.3.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
